import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { i18n } from '@/locales';
import { ref } from 'vue';
import { boxSearchAll } from '@/api/base/box_data';

export const boxTypeList = ref();

export type TableListItem = {
  id: number | string;
  serial: string;
  boxId: string;
  epc: string;
  creatorId: string;
  createTime: string;
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    // @ts-ignore
    title: `冻存盒编号`,
    field: 'serial',
  },
  {
    // @ts-ignore
    title: `冻存盒类型`,
    field: 'boxId',
    formatter: ({ cellValue }) => {
      return boxTypeList.value?.find((item) => item.value === cellValue)?.label ?? '';
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        request: async () => {
          const res = await boxSearchAll();
          return (boxTypeList.value = res.result.map((item) => ({
            label: item.serial,
            value: item.id,
          })));
        },
      },
    },
  },
  {
    // @ts-ignore
    title: i18n.global.t('specimen.epc'),
    field: 'epc',
  },
  {
    title: '创建人',
    field: 'creatorId',
    hideInTable: true,
  },
  {
    title: '创建时间',
    field: 'createTime',
    hideInSearch: true,
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
  },
];
